package com.controller.api;

import com.biz.HomeContentBiz;
import com.biz.HotelHomeBiz;
import com.controller.backend.BaseController;
import com.core.Result;
import com.core.ResultGenerator;
import com.entity.cond.BaseCond;
import com.entity.model.HomeContent;
import com.entity.model.HotelHome;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.util.CalendarUtil;
import com.util.webpage.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jc on 2019/11/16.
 */
@RestController("apiHotelHomeController")
@RequestMapping("/api/hotelHome")
public class HotelHomeController extends BaseController<HotelHome> {
    @Autowired
    private HotelHomeBiz hotelHomeBiz;

    @Autowired
    private HomeContentBiz homeContentBiz;

    //房间详情
    @RequestMapping(value = "/detail")
    public Result detail(@RequestParam Integer hotelHomeId) {
        if (hotelHomeId == null) {
            return ResultGenerator.genFailResult("房间编号不能为空");
        }
        HotelHome hotelHome = hotelHomeBiz.findById(hotelHomeId);
        return ResultGenerator.genSuccessResult(hotelHome);
    }

    //房间列表
    @RequestMapping(value = "/homeList")
    public Result homeList(String cityName, BaseCond bcond) {
        PageHelper.startPage(bcond.getPageNum(), bcond.getPageSize(), false);
        if (cityName.equals("全部")) {
            cityName = null;
        }
        List<HotelHome> hotelHomses = hotelHomeBiz.getIndexHomeList(cityName);
        for (Integer i = 0; i < hotelHomses.size(); i++) {
            hotelHomses.get(i).setHomePhoto(hotelHomses.get(i).getBannerPhoto());
        }
        return ResultGenerator.genSuccessResult(hotelHomses);
    }

    @RequestMapping(value = "/homeContent")
    public Result homeContent() {
        List<HomeContent> solutions = homeContentBiz.homeContent();
        PageInfo<HomeContent> pageInfo = new PageInfo<HomeContent>(solutions);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
